package platform.factory;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

public class ServiceLocator implements BeanFactoryAware {
	
	private static BeanFactory beanFactory;

	@Override
	public void setBeanFactory(BeanFactory arg0) throws BeansException {
		ServiceLocator.beanFactory = arg0;
	}

	public Object getService(String name){
		return beanFactory.getBean(name);
	}
	
	public static <T>T getService(Class<T> name){
		return beanFactory.getBean(name.getSimpleName().substring(0,1).toLowerCase()+name.getSimpleName().substring(1),name);
	}

	public static <T>T getBean(Class<T> name){
		return getService(name);
	}
	
	public BeanFactory getBeanFactory() {
		return beanFactory;
	}
	
}
